import useGetList from "@/hooks/useGetList";
import { getShipList, GetShipListParams } from "@/services/ship";

const useManageUse = () => {
  const getListFC = async (params: GetShipListParams) => {
    try {
      const res = await getShipList(params);
      const { page, length } = params;
      return {
        list: (res.list || []).map((ship, idx) => ({
          ...ship,
          index: idx + 1 + (page - 1) * length,
        })),
        total: res.total || 0,
        page: params.page || 1,
        size: params.length || 15,
      };
    } catch {
      return {
        list: [],
        total: 0,
        page: 1,
        size: 15,
      };
    }
  };

  const {
    list,
    getList,
    loading,
    total,
    page,
    size,
  } = useGetList(getListFC);

  return {
    list,
    getList,
    loading,
    total,
    page,
    size,
  };
};

export default useManageUse;